home *** CD-ROM | disk | FTP | other *** search
- /* PREC Maker - by John Jeppson
-
- This is an MPW C tool which calls PrStlDialog and
- PrJobDialog and then makes a PREC resource from the
- resulting print record.
-
- Execute the following MPW command line:
- makePREC id title destFile
-
- example: makePREC 1001 "my prec" prec.rsrc
-
- Creates <destFile> if it does not already exist.
- Removes/replaces any pre-existing PREC resources
- with the same ID number in <destFile>.
- */
-
-
- #include <Printing.h>
- #include <Files.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <Fonts.h>
-
- THPrint hPrint;
-
- void makePrintRecord()
- {
- Boolean err;
-
- hPrint = (THPrint) NewHandle(sizeof(TPrint));
- if ( hPrint == 0L )
- {
- printf ("Cannot allocate hPrint\n");
- exit(2);
- }
- PrOpen();
- PrintDefault (hPrint);
- err = PrStlDialog (hPrint);
- err = PrJobDialog (hPrint);
- PrClose();
- }
-
- void openDestFile(Str255 rsrcfile)
- {
- CreateResFile (rsrcfile);
- (void) OpenRFPerm (rsrcfile, 0, fsWrPerm);
- if (ResError()) {
- printf ("Cannot open dest file, error# %d", ResError());
- exit(2);
- }
- }
-
-
- void checkPreexisting(ResType theType, short theID)
- {
- SetResLoad (false);
- if (Get1Resource (theType, theID))
- do
- RmveResource (Get1Resource (theType, theID));
- while
- (ResError() == noErr);
- SetResLoad (true);
- }
-
-
- int main (int argc, /* number of arguments */
- char *argv[], /* pointer to array of argument strings */
- char *envp[]) /* pointer to array of variable definitions */
- {
- #pragma unused (envp)
-
- short theID;
- ResType theType;
-
- InitGraf((Ptr) &qd.thePort);
- SetFScaleDisable(true);
-
- if ( argc != 4 )
- {
- printf ("### Wrong Number of Parameters ###\n");
- return 2;
- }
-
- theType = 'PREC';
- theID = (short) atol(argv[1]);
- (void) c2pstr(argv[2]);
- (void) c2pstr(argv[3]);
-
- InitCursor();
- makePrintRecord();
- openDestFile(argv[3]);
- checkPreexisting(theType, theID);
- AddResource ((Handle) hPrint, theType, theID, argv[2]);
-
- return 0;
- }
-
-